﻿<cfsilent>
	<cfscript>
		
		event.setArg("pageTitle", "教学任务安排 - 临时性调停课");
		
		mathAdvice = getProperty("serviceFactory").getBean("senateMathAdvice");
		datetimeAdvice = getProperty("serviceFactory").getBean("datetimeAdvice");
		dictAdvice = getProperty("serviceFactory").getBean("senateDictionaryAdvice");
		
		termId = event.getArg("TermID");
		academicYear = event.getArg("AcademicYear");
		academicTerm = event.getArg("AcademicTerm");
		
		currentTab = event.getArg("TabID", "labSign");
		
		keyword = event.getArg("Keywords");
		rs_programTask = queryNew("tsk_id");
		rs_commonTask = queryNew("tsk_id");
		rs_openTask = queryNew("tsk_id");
	
		passArgs = structNew();
		structInsert( passArgs, "TID", termId );
		
		/* 调课申请 */
		sql = "SELECT 
					t_task_adjust.sign_id, 
					t_task_adjust.change_type, 
					t_task_adjust.change_desc, 
					t_task_adjust.date_created, 
					t_course.course_name, 
					t_teacher.tch_name, 
					t_institute.institute_short 
				FROM 
					t_task_adjust 
					INNER JOIN t_course ON t_course.cid = t_task_adjust.cid 
					INNER JOIN t_teacher ON t_teacher.tch_id = t_task_adjust.sign_user_id 
					INNER JOIN t_institute ON t_institute.institute_id = t_course.institute_id 
				WHERE 
					t_task_adjust.term_id = :termId 
					AND 
					t_task_adjust.sign_status = 'W' 
				ORDER BY 
					t_task_adjust.date_created DESC ";
					
		queryObj = new query( datasource=application.dnsSlave );
		queryObj.addParam( name="termId", value=termId, cfsqltype="cf_sql_char" );
		rs_sign = queryObj.execute( sql=sql ).getResult();
		
		/* 调课历史记录 */
		sql = "SELECT 
					t_task_adjust.sign_id, 
					t_task_adjust.change_type, 
					t_task_adjust.change_desc, 
					t_task_adjust.date_review, 
					t_course.course_name, 
					t_teacher.tch_name, 
					t_institute.institute_short 
				FROM 
					t_task_adjust 
					INNER JOIN t_course ON t_course.cid = t_task_adjust.cid 
					INNER JOIN t_teacher ON t_teacher.tch_id = t_task_adjust.sign_user_id 
					INNER JOIN t_institute ON t_institute.institute_id = t_course.institute_id 
				WHERE 
					t_task_adjust.term_id = :termId 
					AND 
					t_task_adjust.sign_status = 'P' 
				ORDER BY 
					t_task_adjust.date_created DESC ";
					
		queryObj = new query( datasource=application.dnsSlave );
		queryObj.addParam( name="termId", value=termId, cfsqltype="cf_sql_char" );
		rs_history = queryObj.execute( sql=sql ).getResult();
		
		if ( len(keyword) ) {
			
			currentTab = event.getArg("TabID", "labSearch");
			
			sql = "SELECT 
						a.tsk_id,
						t_institute.institute_short, 
						t_course.course_code, 
						a.cidx, 
						t_course.course_name, 
						t_teacher.tch_name, 
						a.task_week, 
						t_campus.campus_name, 
						a.task_time, 
						CASE WHEN a.task_place IS NULL THEN '-/-' ELSE a.task_place END task_place 
					FROM 
						t_task a 
						INNER JOIN t_course ON t_course.cid = a.cid 
						INNER JOIN t_institute ON t_institute.institute_id = t_course.institute_id 
						INNER JOIN t_teacher ON t_teacher.tch_id = a.tch_id 
						INNER JOIN t_campus ON t_campus.campus_id = a.campus_id 
					WHERE 
						a.term_id = :termId 
						AND 
						(
							 t_course.course_code LIKE :condition 
							 OR 
							 t_course.course_name LIKE :condition 
							 OR 
							 t_teacher.tch_id LIKE :condition 
							 OR 
							 t_teacher.tch_name LIKE :condition 
						)
						AND 
						EXISTS(
							 SELECT 1 FROM t_task_arrange b 
							 WHERE 
									b.task_id = a.tsk_id 
									AND 
									b.term_id = :termId 
									AND 
									b.period_done > 0 
						)
					ORDER BY 
					   t_course.course_name, a.cidx ";
					   
			queryObj = new query( datasource=application.dnsSlave );
			queryObj.addParam( name="condition", value=keyword&"%", cfsqltype="cf_sql_varchar" );
			queryObj.addParam( name="termId", value=termId, cfsqltype="cf_sql_char" );
			rs_programTask = queryObj.execute( sql=sql ).getResult();
		
			sql = "SELECT 
						a.tsk_id, 
						t_institute.institute_short, 
						t_course.course_code, 
						a.cidx, 
						t_course.course_name, 
						t_teacher.tch_name, 
						a.task_week, 
						t_campus.campus_name, 
						a.task_time, 
						CASE WHEN a.task_place IS NULL THEN '-/-' ELSE a.task_place END task_place 
					FROM 
						t_common_task a 
						INNER JOIN t_course ON t_course.cid = a.cid 
						INNER JOIN t_institute ON t_institute.institute_id = t_course.institute_id 
						INNER JOIN t_teacher ON t_teacher.tch_id = a.tch_id 
						INNER JOIN t_campus ON t_campus.campus_id = a.campus_id 
					WHERE 
						a.term_id = :termId 
						AND 
						(
							 t_course.course_code LIKE :condition 
							 OR 
							 t_course.course_name LIKE :condition 
							 OR 
							 t_teacher.tch_id LIKE :condition 
							 OR 
							 t_teacher.tch_name LIKE :condition 
						)
						AND 
						EXISTS(
							 SELECT 1 FROM t_task_arrange b 
							 WHERE 
									b.task_id = a.tsk_id 
									AND 
									b.term_id = :termId 
									AND 
									b.period_done > 0 
						)
					ORDER BY 
					   t_course.course_name, a.cidx ";
					   
			queryObj = new query( datasource=application.dnsSlave );
			queryObj.addParam( name="condition", value=keyword&"%", cfsqltype="cf_sql_varchar" );
			queryObj.addParam( name="termId", value=termId, cfsqltype="cf_sql_char" );
			rs_commonTask = queryObj.execute( sql=sql ).getResult();
		
			sql = "SELECT 
						a.tsk_id, 
						t_institute.institute_short, 
						t_course.course_code, 
						a.cidx, 
						t_course.course_name, 
						t_teacher.tch_name, 
						a.task_week, 
						t_campus.campus_name, 
						a.task_time, 
						CASE WHEN a.task_place IS NULL THEN '-/-' ELSE a.task_place END task_place 
					FROM 
						t_reopen_task a 
						INNER JOIN t_course ON t_course.cid = a.cid 
						INNER JOIN t_institute ON t_institute.institute_id = t_course.institute_id 
						INNER JOIN t_teacher ON t_teacher.tch_id = a.tch_id 
						INNER JOIN t_campus ON t_campus.campus_id = a.campus_id 
					WHERE 
						a.term_id = :termId 
						AND 
						(
							 t_course.course_code LIKE :condition 
							 OR 
							 t_course.course_name LIKE :condition 
							 OR 
							 t_teacher.tch_id LIKE :condition 
							 OR 
							 t_teacher.tch_name LIKE :condition 
						)
						AND 
						EXISTS(
							 SELECT 1 FROM t_task_arrange b 
							 WHERE 
									b.task_id = a.tsk_id 
									AND 
									b.term_id = :termId 
									AND 
									b.period_done > 0 
						)
					ORDER BY 
					   t_course.course_name, a.cidx ";
					   
			queryObj = new query( datasource=application.dnsSlave );
			queryObj.addParam( name="condition", value=keyword&"%", cfsqltype="cf_sql_varchar" );
			queryObj.addParam( name="termId", value=termId, cfsqltype="cf_sql_char" );
			rs_openTask = queryObj.execute( sql=sql ).getResult();
			
		}
		
	</cfscript>
</cfsilent>

<div id="headArea">
	<div class="uiHeader uiHeaderWithImage ptm">
		<div class="clearfix uiHeaderTop">
			<div class="uiHeaderActions rfloat">
				<a class="uiButton" href="<cfoutput>#buildURL('DEFAULT_EVENT')#</cfoutput>"><i class="mrs img btnList"></i><span class="uiButtonText">教学任务安排</span></a>
			</div>
			<div>
				<h2 class="uiHeaderTitle">
					<i class="uiHeaderImage img icon16x16 card"></i>临时性调停课
				</h2>
			</div>
		</div>
	</div>
</div>

<div class="UIElement">
	<ul class="senateFirstPage">
		<li>
			<div class="clearfix" id="summary">
				<div class="UItab">
					<div class="tabLables">
						<span <cfif currentTab eq "labSearch">class="active"</cfif> id="labSearch" tabTarget="Search">选择教学任务</span>
						<span <cfif currentTab eq "labSign">class="active"</cfif> id="labSign" tabTarget="Sign">调课申请</span>
						<span <cfif currentTab eq "labRecord">class="active"</cfif> id="labRecord" tabTarget="Record">历史记录</span>
					</div>
				</div>
				<script language="javascript" type="text/javascript">
					//<![CDATA[
					<!--
					$(document).ready(function() {
						
						/* init Tab */
						$("div.tabContent").hide();
						$("div#" + $("div.tabLables span.active").attr("tabTarget")).show();
						
						$("div.tabLables > span").click(function(){
							var $targetID = $(this).attr("tabTarget");
							
							$("div.tabLables span").removeClass("active");
							$(this).addClass("active");
							
							$("div.tabContent").not('[id="' + $targetID + '"]').hide();
							$("div.tabContent#" + $targetID).show();
						});
						
					});
					// -->
					//]]>
				</script>

				<div id="Search" class="tabContent">

					<form id="formSearch" onSubmit="javascript:return processVerfiyForm('formSearch');" class="formWrapper Transparent" method="post" action="<cfoutput>#buildURL('taskTempChange')#</cfoutput>" />
						<div class="label">
							<b>教师姓名或职工号</b>
							<input name="Keywords" id="Keywords" type="text" class="typeText" verification="required" maxlength="128" value="<cfoutput>#event.getArg('Keywords')#</cfoutput>" />
							<p class="notice">可以根据教师、职工号或课程名称、课程代码进行教学任务查找</p>
						</div>
						<hr/>
						<div class="lable">
							<input class="button" type="submit" value="搜索教学任务" />
						</div>
					</form>
					
					<cfif rs_programTask.recordCount or rs_commonTask.recordCount or rs_openTask.recordCount>
							
							<table id="taskList" class="UIEditable">
								<thead>
									<tr>
										<td></td>
										<td>任课单位</td>
										<td>教学班</td>
										<td>主讲教师</td>
										<td>校区</td>
										<td>周次</td>
										<td>上课时间</td>
										<td>上课地点</td>
										<td width="18"></td>
									</tr>
								</thead>
								<tbody>
									
									<cfset row = 0 />
									<cfset structInsert( passArgs, "TT", "P", true ) />
                                    <cfloop query="rs_programTask">
										<cfset structInsert( passArgs, "TSK", rs_programTask.tsk_id, true ) />
										<cfset row++ />
										<tr class="editRows">
											<td class="index">P.<cfoutput>#row#</cfoutput></td>
											<td><cfoutput>#rs_programTask.institute_short#</cfoutput></td>
											<td><cfoutput>#rs_programTask.course_name#</cfoutput><span class="numeric">-<cfoutput>#rs_programTask.cidx#</cfoutput></span></td>
											<td><cfoutput>#rs_programTask.tch_name#</cfoutput></td>
											<td><cfoutput>#rs_programTask.campus_name#</cfoutput></td>
											<td><span class="numeric"><cfoutput>#rs_programTask.task_week#</cfoutput></span></td>
											<td><cfoutput>#replace( mathAdvice.convertTaskTime(rs_programTask.task_time), ",", "<br/>", "all")#</cfoutput></td>
											<td><cfoutput>#replace( rs_programTask.task_place, ",", "<br/>", "all")#</cfoutput></td>
											<td><a href="<cfoutput>#buildURL('taskChangeWizard', passArgs)#</cfoutput>" class="stat config"></a></td>
										</tr>
									</cfloop>
									
									<cfset row = 0 />
									<cfset structInsert( passArgs, "TT", "C", true ) />
                                    <cfloop query="rs_commonTask">
										<cfset structInsert( passArgs, "TSK", rs_commonTask.tsk_id, true ) />
										<cfset row++ />
										<tr class="editRows">
											<td class="index">C.<cfoutput>#row#</cfoutput></td>
											<td><cfoutput>#rs_commonTask.institute_short#</cfoutput></td>
											<td><cfoutput>#rs_commonTask.course_name#</cfoutput><span class="numeric">-<cfoutput>#rs_commonTask.cidx#</cfoutput></span></td>
											<td><cfoutput>#rs_commonTask.tch_name#</cfoutput></td>
											<td><cfoutput>#rs_commonTask.campus_name#</cfoutput></td>
											<td><span class="numeric"><cfoutput>#rs_commonTask.task_week#</cfoutput></span></td>
											<td><cfoutput>#replace( mathAdvice.convertTaskTime(rs_commonTask.task_time), ",", "<br/>", "all")#</cfoutput></td>
											<td><cfoutput>#replace( rs_commonTask.task_place, ",", "<br/>", "all")#</cfoutput></td>
											<td><a href="<cfoutput>#buildURL('taskChangeWizard', passArgs)#</cfoutput>" class="stat config"></a></td>
										</tr>
									</cfloop>
									
									<cfset row = 0 />
									<cfset structInsert( passArgs, "TT", "R", true ) />
                                    <cfloop query="rs_openTask">
										<cfset structInsert( passArgs, "TSK", rs_openTask.tsk_id, true ) />
										<cfset row++ />
										<tr class="editRows">
											<td class="index">R.<cfoutput>#row#</cfoutput></td>
											<td><cfoutput>#rs_openTask.institute_short#</cfoutput></td>
											<td><cfoutput>#rs_openTask.course_name#</cfoutput><span class="numeric">-<cfoutput>#rs_openTask.cidx#</cfoutput></span></td>
											<td><cfoutput>#rs_openTask.tch_name#</cfoutput></td>
											<td><cfoutput>#rs_openTask.campus_name#</cfoutput></td>
											<td><span class="numeric"><cfoutput>#rs_openTask.task_week#</cfoutput></span></td>
											<td><cfoutput>#replace( mathAdvice.convertTaskTime(rs_openTask.task_time), ",", "<br/>", "all")#</cfoutput></td>
											<td><cfoutput>#replace( rs_openTask.task_place, ",", "<br/>", "all")#</cfoutput></td>
											<td><a href="<cfoutput>#buildURL('taskChangeWizard', passArgs)#</cfoutput>" class="stat config"></a></td>
										</tr>
									</cfloop>
									
								</tbody>
							</table>
							
						<cfelseif len(keyword)>
							<div class="systemNotice">
								<p>没有符合条件的排课任务</p>
							</div>
					</cfif>

				</div>

				<div id="Sign" class="tabContent">
					
					<div class="noticeBlock">
						<h3>待审批的调课申请</h3>
					</div>
					
					<cfif rs_sign.recordCount>
						
						<cfelse>
							<div class="systemNotice">
								<p>所有的调停课申请已处理完毕</p>
							</div>
					</cfif>
					
				</div>
				
				<div id="Record" class="tabContent">
					
					<div class="noticeBlock">
						<h3>调停课历史记录</h3>
					</div>
					
					<cfif rs_history.recordCount>
							
							<table id="historyList" class="UIEditable">
								<thead>
									<tr>
										<td></td>
										<td>类别</td>
										<td>任课单位</td>
										<td>教学班</td>
										<td>描述</td>
										<td>审批时间</td>
										<td width="18"></td>
									</tr>
								</thead>
								<tbody>
									<cfset row = 0 />
									<cfset viewArgs = structNew() />
                                    <cfloop query="rs_history">
										<cfset row++ />
										<cfset structInsert( viewArgs, "DOCID", rs_history.sign_id, true ) />
										<tr class="editRows">
											<td class="index"><cfoutput>#row#</cfoutput></td>
											<td><cfoutput>#dictAdvice.getTaskChangeType( rs_history.change_type )#</cfoutput></td>
											<td><cfoutput>#rs_history.institute_short#</cfoutput></td>
											<td><cfoutput>#rs_history.course_name#</cfoutput>-<cfoutput>#rs_history.tch_name#</cfoutput></td>
											<td><cfoutput>#rs_history.change_desc#</cfoutput></td>
											<td><span class="numeric"><cfoutput>#datetimeAdvice.formatDateString( rs_history.date_review )#</cfoutput></span></td>
											<td><a href="<cfoutput>#buildURL('taskTempChangeHistory', viewArgs)#</cfoutput>" class="stat info"></a></td>
										</tr>
									</cfloop>
								</tbody>
							</table>
							
						<cfelse>
							<div class="systemNotice">
								<p>尚无存档记录</p>
							</div>
					</cfif>
					
				</div>
				
			</div>
		</li>
	</ul>
</div>


